﻿Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Imports Microsoft.SqlServer.Server

Partial Public Class StoredProcedures

    'Simple example of a CmdShell Call with parameters
    <Microsoft.SqlServer.Server.SqlProcedure()> _
    Public Shared Function MSPExecFTPCmd() As Integer
        Dim _sFileNameWithPath As String
        Dim _sCmdArguments As String

        'Just the ftp command, returns all the options
        _sFileNameWithPath = "ftp.exe"
        _sCmdArguments = "/?"

        SqlContext.Pipe.Send("------ > Execution Starts < ------")

        Try
            Dim _oStdOut As System.IO.StreamReader
            Dim _oStdErr As System.IO.StreamReader

            CmdExecWithArguments(_sFileNameWithPath, _sCmdArguments, _oStdOut, _oStdErr)

            OutputResults("--- > Output StdOut < ---", _oStdOut)
            OutputResults("--- > Output StdErr < ---", _oStdErr)

            SqlContext.Pipe.Send(vbCrLf & "------- > Execution Ends < -------")
        Catch ex As Exception
            ShowError(ex.ToString)

            Return 1
        End Try
    End Function
End Class
